export const downloadAudio = function (url, fileName) {
  // 走nginx代理，避免跨域
  fetch(url.replace('https://pro-ccrecords.kefutoutiao.com', '')).then(res => res.blob()).then(blob => {
    const a = document.createElement('a');
    document.body.appendChild(a)
    a.style.display = 'none'
    // 使用获取到的blob对象创建的url
    const url = window.URL.createObjectURL(blob);
    a.href = url;
    // 指定下载的文件名
    a.download = fileName;
    a.click();
    document.body.removeChild(a)
    // 移除blob对象的url
    window.URL.revokeObjectURL(url);
  });
}

export function downloadExcel(blob, fileName = 'download.xls') {
  const elink = document.createElement('a')
  elink.innerHTML = fileName;
  elink.download = fileName
  elink.style.display = 'none'
  elink.href = URL.createObjectURL(blob)
  document.body.appendChild(elink)
  elink.click()
  setTimeout(() => {
    document.body.removeChild(elink)
  }, 2000);
}

export function objectToQueryString(obj){
  let str=[]
  for(var k in obj){
    str.push(`${k}=${obj[k]}`)
  }
  return str.join('&')
}